package com.example.project.volley;

import android.content.Context;
import android.graphics.Bitmap;

import com.android.volley.Response;
import com.android.volley.VolleyError;

import org.json.JSONException;

//抽象类
public abstract class VolleyInterface {
    public Context context; //上下文对象
    public static Response.Listener<String> listener; //成功访问
    public static Response.ErrorListener errorListener; //失败访问
    public static Response.Listener<Bitmap> imagelistener; //访问图片

    public VolleyInterface(Context context){
        this.context=context;
        this.listener=listener;
        this.errorListener=errorListener;
    }

    //实现网络访问成功回调
    public abstract void onMySuccess(String result) throws JSONException;
    public Response.Listener<String> loadingListerner(){
        listener=new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                try {
                    onMySuccess(s);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        };
        return listener;
    }

    //实现网络访问失败回调
    public abstract void onMyError(VolleyError error);
    public Response.ErrorListener errorListener(){
        errorListener=new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                onMyError(volleyError);
            }
        };
        return errorListener;
    }

    //实现网络访问图片回调
    public abstract void onImageSuccess(Bitmap bitmap);
    public Response.Listener<Bitmap> Imagelistener(){
        imagelistener=new Response.Listener<Bitmap>() {
            @Override
            public void onResponse(Bitmap bitmap) {
                onImageSuccess(bitmap);
            }
        };
        return imagelistener;
    }
}
